package com.ibuonline.b2b.common.importer;
import java.io.File;
import java.io.FilenameFilter;

public class PickPictures {
	
	public static void main(String[] args) throws Exception {
		//System.out.print("::::aa\b");
		//System.out.print("cc");
		
		//if (true) return;
		String src = "I:/pic2011/webs/518AD-lb2009-pic/PicFolder/ProductPic";
		File[] folders = new File(src).listFiles(new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return Integer.parseInt(name) >= 20100806;
			}
		});
		Runtime rt = Runtime.getRuntime();
		String[] backspaces = {"\b", "\b\b", "\b\b\b", "\b\b\b\b", "\b\b\b\b\b"};
		for (File folder : folders) {
			File[] files = new File(src + "/" +  folder.getName()).listFiles(new FilenameFilter() {
				public boolean accept(File dir, String name) {
					name = name.toLowerCase();
					return name.indexOf("_s.") == -1 && name.indexOf("_m.") == -1;
				}
			});
			int j = 0;
			File parentFolder = null;
			System.out.print(folder.getName() + ": ");
			for (File file : files) {
				String srcPath = file.getAbsolutePath();
				String desPath = srcPath.replace("ProductPic", "ProductPic20100806");
				String parent = desPath.substring(0, desPath.lastIndexOf('\\'));
				if (parentFolder == null) {
					parentFolder = new File(parent);
					parentFolder.mkdirs();
				}
				if (j % 1000 == 0) {
					rt.exec("cmd /c move " + srcPath + " " + parent).waitFor();
				} else {
					rt.exec("cmd /c move " + srcPath + " " + parent);
				}
				System.out.print(++j);
				System.out.print(backspaces[(int)Math.log10(j)]);
			}
			System.out.println();
		}
	}
	
	
}
